/**
 * 
 */
package com.cn.practice.builder;

/**
 * 建造者模式-建房子都有一些相同的流程 
 * 但是却能建造出不同的房子
 * 建造者核心 产品 抽象建造者(包工头) 具体建造者(施工队)，项目协调者(甲方)
 * 核心逻辑:包工头有方法能建造出房子，而具体建造又施工队安城 甲方只需要找到包工头，安排自己施工流程
 * 包工头交给施工队就等得到自己对应的房子
 * @author zhangyang
 *
 */
public class BuilderPractice {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		//使用具体建造者
		smallHeightBuilder heightBuilder = new smallHeightBuilder();
		//使用协调者
		buildEditor editor = new buildEditor();
		Building building = editor.editor(heightBuilder);
		System.out.println(building);
	}

}
/**
 * 抽象类 建筑
 * @author zhangyang
 *
 */
class Building{
	String basic;
	String wall;
	String roof;
	@Override
	public String toString() {
		return "Building [basic=" + basic + ", wall=" + wall + ", roof=" + roof + "]";
	}
	
	
}


/**
 * 抽象建筑类-建成一个抽象房子
 * @author zhangyang
 *
 */
abstract class BuildingBuilder{
	Building building=new Building();
	abstract void buildBasic();
	abstract void buildWall();
	abstract void buildRoof();
	public Building buildHouse() {
		return building;
	}
}

/**
 * 小高层建造者
 * @author zhangyang
 *
 */
class smallHeightBuilder extends BuildingBuilder{

	@Override
	void buildBasic() {
		// TODO Auto-generated method stub
		this.building.basic="3米";
		System.out.println("开始给小高层打地基");
	}


	@Override
	void buildWall() {
		// TODO Auto-generated method stub
		this.building.wall="青砖墙";
		System.out.println("开始给小高层砌墙");
	}

	@Override
	void buildRoof() {
		// TODO Auto-generated method stub
		this.building.roof="混凝土";
		System.out.println("开始给小高层封顶");
	}
	
}

/**
 * 协调者
 * @author zhangyang
 *
 */
class buildEditor{
	
	public Building editor(BuildingBuilder builder) {
		builder.buildBasic();
		builder.buildWall();
		builder.buildRoof();
		return builder.buildHouse();
	}
}